var gulp = require("gulp");
var sass = require("gulp-sass");
var browserSync = require("browser-sync");
var useref = require("gulp-useref");
var uglify = require("gulp-uglify");
//转化css
gulp.task('sass',function(){
	return gulp.src('src/app/scss/*.scss')
	.pipe(sass())
	.pipe(gulp.dest('src/app/css'))
	.pipe(browserSync.reload({stream : true}))
});
//同步
gulp.task('browserSync',function(){
	return browserSync({
         server:{
         	baseDir:'src/app'
         }
	 })
});
//监听
gulp.task('watch',['sass','browserSync'],function(){
	 gulp.watch('src/app/scss/*.scss',['sass']);
	 gulp.watch('src/app/*.html',browserSync.reload);
	 gulp.watch('src/app/jsbank/*.js',browserSync.reload);
});
gulp.task('html',function(){
   var options = {
    removeComments: true,//清除HTML注释
    collapseWhitespace: true,//压缩HTML
    collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
    removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
    removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
    removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
    minifyJS: true,//压缩页面JS
    minifyCSS: true//压缩页面CSS
}
    gulp.src('src/app/*.html')
   
    .pipe(gulp.dest('./dist'))
    .pipe(browserSync.reload({
      stream: true
    }));

});
gulp.task('default',['browserSync','sass','watch','html']);



//拼接
gulp.task('useref',function(){
          return gulp.src('app/*.html')
          .pipe(useref())
          .pipe(gulp.dest('dist'))
});
//压缩
gulp.task('uglify',function(){
          return gulp.src('dist/js/*.js')
          .pipe(uglify())
          .pipe(gulp.dest('dist/minjs'))
});